package com.jml.zlhq.app.adapter;

import java.util.List;

import com.jml.zlhq.app.AppContext;
import com.jml.zlhq.app.R;

import android.app.Activity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

public class DownTaskAdapter extends IBaseAdapter {
	private List<Object[]> itemList;
	private AppContext appContext;

	public DownTaskAdapter(Activity activity, List<Object[]> itemList) {
		this.itemList = itemList;
		this.appContext = (AppContext) activity.getApplication();
	}

	@Override
	public int getCount() {
		int count  = itemList == null ? 0 : itemList.size();
		return count;
	}

	@Override
	public Object getItem(int position) {
		return itemList.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}
	
	static class ViewHolder {
		public TextView name,info;
		public ImageView img;
	}

	@Override
	public View getView(int position, View convertView, final ViewGroup parent) {
		
		ViewHolder viewHolder = null;
		if (convertView == null) {
			viewHolder = new ViewHolder();
			int layoutId = R.layout.down_task_item;
			convertView = LayoutInflater.from(appContext).inflate(layoutId, null);
			viewHolder.name = (TextView) convertView.findViewById(R.id.down_tast_item_name);
			viewHolder.info = (TextView) convertView.findViewById(R.id.down_tast_item_info);
			viewHolder.img = (ImageView) convertView.findViewById(R.id.down_tast_item_img);
			convertView.setTag(viewHolder);
		} else {
			viewHolder = (ViewHolder) convertView.getTag();
		}
		viewHolder.name.setText(itemList.get(position)[1].toString());//Padding(0, UIUtil.dip2px(appContext, 18), 0, UIUtil.dip2px(appContext, 18));
		viewHolder.info.setText(itemList.get(position)[3].toString());
		viewHolder.img.setImageResource(Integer.parseInt(itemList.get(position)[2].toString()));

		return convertView;
	}

}
